home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 2922 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.5 KB  |  43 lines

  1. Path: news.clark.net!not-for-mail
  2. From: gusty@clark.net (Harlan Messinger)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Q:order of evaluation
  5. Date: 20 Jan 1996 00:20:08 GMT
  6. Organization: Clark Internet Services, Inc., Ellicott City, MD USA
  7. Message-ID: <4dpcfo$293@clarknet.clark.net>
  8. References: <4dfhlu$a33$1@mhafn.production.compuserve.com> <hamilton-1801962045570001@dialup-147.austin.io.com>
  9. NNTP-Posting-Host: explorer.clark.net
  10. Mime-Version: 1.0
  11. Content-Type: TEXT/PLAIN; charset=ISO-8859-1
  12. Content-Transfer-Encoding: 8bit
  13. X-Newsreader: TIN [UNIX 1.3 950726BETA PL0]
  14.  
  15. Jim Hamilton (hamilton@shokwave.com) wrote:
  16. : In article <4dfhlu$a33$1@mhafn.production.compuserve.com>, Holger Maier
  17. : <100336.3326@CompuServe.COM> wrote:
  18. : >Consider
  19. : >#include <iostream>
  20. : >int main() {
  21. : >  int i=1;int j=i+(i+=1);
  22. : >  cout<<i<<','<<j<<'\n';
  23. : >  return 0;
  24. : >}
  25. : >on my compiler this produces 2,4
  26. : >Looked up the ARM:
  27. : >5: .. The order of evaluation of subexpressions is determined by the
  28. : >precedence and grouping of operators.
  29. : >5.7: The additive operators + and - group left to right.
  30. : >So, j should be assigned 3 ??
  31. : >Now the question to you C++ gurus out there on the nets:
  32. : >Is it really a compiler bug or is it just me misinterpreting the 
  33. : >ARM?
  34. : >BTW: I know we should not code like that...
  35. : >Holger
  36. : The highest precedence in any expression is the insides of parentheses
  37. : ().  Therefore (i+=1) is evaluated before i+().
  38.  
  39. True, but that's not actually the problem here. The problem is whether 
  40. (i+=1) gets evaluated before the i to the left of the plus sign.
  41.